﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeSaveNewPRDataAction : BestLifeDataAction<int>
    {

        private Purchase_Request GvPR;
        private string Gvxml;

        public BestLifeSaveNewPRDataAction(Purchase_Request PPR, string Pxml)
        {

            GvPR = PPR;
            Gvxml = Pxml;

        }

        public override int Body(SqlConnection PConn)
        {
            try
            {

                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.InsertPRDetails";

                LvCommand.Parameters.Add(new SqlParameter("@PR_No", GvPR.Pr_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Branch_Name", GvPR.Branch_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Required_Date", DateTime.Parse(GvPR.Accept_Date.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@Description", GvPR.Description.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Total", decimal.Parse(GvPR.Total.ToString())));
                LvCommand.Parameters.Add(new SqlParameter("@User_Create", GvPR.User_Id.ToString()));
                LvCommand.Parameters.Add(new SqlParameter("@Create_Date", DateTime.Parse(GvPR.Create_Date.ToString())));

                LvCommand.Parameters.Add(new SqlParameter("@prdetails", Gvxml));


                int LvCount = LvCommand.ExecuteNonQuery();
                return LvCount; 

            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
